package xainchenggaoji;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author Mr.ma
 * @since 2022/11/2 21:27
 * 常用方法：
 *       void shutdown(); 关闭线程池
 *       List<Runnable> shutdownNow(); 关闭等待的任务
 *       boolean isShutdown(); 判断线程池是否关闭
 *       boolean isTerminated();判断线程池是否终止，表示任务是否执行完。
 *       <T> Future<T> submit(Callable<T> task); 提交Callable类型的任务给线程池。
 *       Future<?> submit(Runnable task); 提交Runnable类型的任务给线程池
 **/
public class ExecutorMethod {
    public static void main(String[] args) {
        ExecutorService executorService = Executors.newFixedThreadPool(5);
        for (int i = 0; i < 10; i++) {
            final  int a=i;
            executorService.submit(new Runnable() {
                @Override
                public void run() {
                    System.out.println(Thread.currentThread().getName()+"====="+a);
                }
            });
        }
        //关闭线程池
        executorService.shutdown();
        //判断线程池是否关闭
        boolean shutdown = executorService.isShutdown();
        System.out.println(shutdown);
        //判断线程池是否终止
        boolean terminated = executorService.isTerminated();
        System.out.println(terminated);

    }
}
